package com.xindaoapp.happypet.activity;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;
import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.protocol.MoccaApi;
import com.xindaoapp.happypet.protocol.MoccaApiImpl;

@Deprecated
public class BaseActivity extends FragmentActivity {
    private MoccaApi mMoccaApi;

    @Override
    protected void onStart() {
        super.onStart();
        mMoccaApi = new MoccaApiImpl();
        View back = findViewById(R.id.tittle_common_cancel);
        if (null != back) {
            back.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }

        setTabTitle(getTabTitle());
    }

    protected MoccaApi getMoccaApi() {
        return mMoccaApi;
    }

    protected final void showKeyBoard() {
        InputMethodManager inputManager =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInputFromInputMethod(getWindow().getDecorView().getWindowToken(), 0);
    }

    /**
     * 获取标题内容
     * 
     * @return
     */
    protected Object getTabTitle() {
        return null;
    }

    /**
     * 设置标题
     * 
     * @param obj
     */
    protected void setTabTitle(Object obj) {
        TextView title = (TextView) findViewById(R.id.title);
        if (null != title) {
            if (obj instanceof Integer) {
                title.setText(Integer.parseInt(obj.toString()));
            } else if (obj instanceof String) {
                title.setText((String) obj);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImageLoader.getInstance().clearMemoryCache();
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(getPackageName());
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getPackageName());
        MobclickAgent.onPause(this);
    }
}
